
#include <BScrollBar>
#include "member_BScrollBar.h"

using namespace BWE;

member_BScrollBar::member_BScrollBar(BScrollBar* scrollBar)
{
	boss = scrollBar;
	value = 0;
	page = 10;
	range.set(0, 100);
	step = 1;
	orientation = Orientation_Horizontal;
	pressed = false;
	draging = false;
	hoverHandle = false;
	dirty = true;
}
member_BScrollBar::~member_BScrollBar()
{

}

void member_BScrollBar::freshHandleRect()
{
	BRect crect = boss->centerRect();
	int cx = crect.x();
	int cy = crect.y();
	int cw = crect.width();
	int ch = crect.height();

	if(page > range.size())
		page = range.size();
	if (value < range.min())
		value = range.min();
	if (value > range.max() - page)
		value = range.max() - page;

	if(orientation == Orientation_Horizontal)
	{
		float width = float(range.size());
		int x = (int)(cx + cw * (value - range.min()) / width);
		int w = (int)(cw * page / width);
		handleRect.set(x, cy, w, ch);
	}
	if(orientation == Orientation_Vertical)
	{
		float height = float(range.size());
		int y = (int)(cy + ch * (value - range.min()) / height);
		int h = (int)(ch * page / height);
		handleRect.set(cx, y, cw, h);
	}
}
